package com.shuqi.activity.viewport;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

import com.shuqi.activity.BookContentActivity;
import com.shuqi.activity.BookContentMoreSetActivity;
import com.shuqi.activity.adapter.PayBcMenuThemAdapter;
import com.shuqi.activity.viewport.HorizontialListView.OnBorderListener;
import com.shuqi.application.ShuqiApplication;
import com.shuqi.common.Constant;
import com.shuqi.common.PayTheme;
import com.shuqi.common.utils.Log4an;
import com.shuqi.common.utils.SharedPreferenceUtil;
import com.shuqi.common.utils.ToastUtil;
import com.shuqi.common.utils.Util;
import com.shuqi.controller.R;
import com.shuqi.model.BookContentModel;
import com.shuqi.model.BookContentSettings;
import com.shuqi.statistics.StatisticsEventID;
import com.shuqi.statistics.StatisticsUtils;

/**
 * 菜单自定义View
 */
public class BookContentMenuView extends FrameLayout implements OnItemClickListener,
        OnBorderListener, OnClickListener, OnSeekBarChangeListener {
    /** 阅读页对象 */
    private Activity mActivity;
    /** 设置对象 */
    private BookContentSettings mSettings;

    /** 菜单动画持续时间 */
    private long mDuration = 200;
    /** 菜单顶部进入动画 */
    private Animation mTopInAnimation;
    /** 菜单顶部弹出动画 */
    private Animation mTopOutAnimation;
    /** 菜单底部进入动画 */
    private Animation mBottomInAnimation;
    /** 菜单底部弹出动画 */
    private Animation mBottomOutAnimation;
    /** 菜单时间监听 */
    private OnMenuEventListener mOnMenuEventListener;

    /** 日间屏幕亮度seekbar */
    private SeekBar mLightBar;
    /** 夜间屏幕亮度seekbar */
    private SeekBar mNightLightBar;
    /** 日间跳转进度seekbar */
    private shuqiDefineSeekBar mJumpBar;
    /** 夜间跳转进度 */
    private shuqiDefineSeekBar mJumpBarNight;
    /** 倒数第二次跳转的百分比进度 */
    private float mLastJumpProgress1;
    /** 最后一次次跳转的百分比进度 */
    private float mLastJumpProgress2;
    /** 跳转百分比显示 */
    private TextView mHint1;
    private TextView mHint2;
    /** 返回跳转上一次的进度 */
    private ImageView mJumpBackImageView;

    private final int MENU_MSG_GONE = 0;
    private final int MENU_MSG_PROGRESS_GONE = 2;

    /** 菜单布局：0-->顶部和设置、目录；1-->调节字号、更多设置 */
    public int mWhich;

    /* 底部菜单 */
    /** 设置 */
    private TextView mBottomMenuSetting_tv;
    /** 夜间 */
    private TextView mBottomMenuNightMode_tv;
    /** 目录 */
    private TextView mBottomMenuCatalog_tv;
    /** 转屏 */
    private TextView mBottomMenuScreen_tv;

    /* 顶部菜单 */
    /** 返回按钮 */
    private View mTopMenuBack_view;
    /** 书架 */
    private View mTopMenuShelf_view;
    /** 封面 */
    private View mTopMenuCover_view;
    /** 来源地址显示 */
    private TextView mChapterUrl_tv;

    /** 底部menu布局 */
    private LinearLayout mBottomMenuLinearLayout;
    // 开始拖动进度可见，两秒后消失，一级重新吊起后不可见并移除消息
    private LinearLayout mBottomMenuProgressLayout;
    private LinearLayout mBottomMenuBottomLayout;

    /** 顶部menu布局 */
    private LinearLayout mTopMenuLinearLayout;

    /** 更多设置布局 */
    /** 主题切换 */
    private HorizontialListView mThemListView;
    private ImageView mThemeMoreImageView;
    /** 主题选择适配器 */
    private PayBcMenuThemAdapter mThemeAdapter;
    private LinearLayout mMoreSettingLinearLayout;
    /** 主题布局 */
    private RelativeLayout mTheme0_relLayout, mTheme1_reLayout, mTheme2_reLayout, mTheme3_reLayout,
            mTheme4_reLayout, mTheme5_reLayout, mTheme6_reLayout, mTheme7_reLayout;
    /** 主题图片 */
    private ImageView mTheme0_img, mTheme1_img, mTheme2_img, mTheme3_img, mTheme4_img, mTheme5_img,
            mTheme6_img, mTheme7_img, mTheme0_img_bg, mTheme1_img_bg, mTheme2_img_bg,
            mTheme3_img_bg, mTheme4_img_bg, mTheme5_img_bg, mTheme6_img_bg, mTheme7_img_bg;
    /** 风格图片 */
    private ImageView mImageStyle1, mImageStyle2, mImageStyle3;
    private TextView mTextStyleDefault;



    /** theme是否要滑到底部 */
    boolean mIsThemeBottom = true;

    /** 系统按钮 */
    private ImageView mSystemBtn;
    /** 小亮度图片 */
    private ImageView mSmallImageView;
    /** 大亮度图片 */
    private ImageView mBigImageView;
    /** 增大字体 */
    private ImageView mAddTextSizeImageView;
    /** 减小字体 */
    private ImageView mReduceTextSizeImageView;
    /** 上一章 */
    private ImageView mPrePageImageView;
    /** 下一章 */
    private ImageView mNextPageImageView;

    private JumpChapterThread mDoJumpChapterThread;

    /** 用来延迟隐藏菜单的handler */
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(android.os.Message msg) {
            switch (msg.what) {
                case MENU_MSG_GONE:// 隐藏菜单
                    setVisibility(View.GONE);
                    if (SharedPreferenceUtil.getInstanceSharedPreferenceUtil()
                            .getBookContentFullScreen()) {
                        setFullScreen(true);
                    }
                    break;
                case MENU_MSG_PROGRESS_GONE:
                    dismissProgress();
                    break;
            }
        };
    };

    /** 需求：进度每次显示，点击进度不动，撤销不可用。进度不消失时，点击进度，进度可用，回到重复点击之前的返回进度 */
    private boolean initBack = true;

    private void dismissProgress() {
        mBottomMenuProgressLayout.setVisibility(View.GONE);
        mHandler.removeMessages(MENU_MSG_PROGRESS_GONE);
        initBack = true;
    }

    private void showProgress() {
        mBottomMenuProgressLayout.setVisibility(View.VISIBLE);
        mHandler.removeMessages(MENU_MSG_PROGRESS_GONE);
    }
    
    public boolean isProgressShow(){
        return (mBottomMenuProgressLayout.getVisibility() == View.VISIBLE)?true:false;
    }

    public void setJumpSeekBarDisable() {
        mJumpBar.setResopnseTouch(false);
        mJumpBarNight.setResopnseTouch(false);
        mJumpBar.setEnabled(false);
        mJumpBarNight.setEnabled(false);

        if (mSettings.isNightMode()) {
            // 上一章下一章按钮的显示颜色
            mPrePageImageView.setImageResource(R.drawable.btn_menu_pre_charpter_night_no);
            mNextPageImageView.setImageResource(R.drawable.btn_menu_next_charpter_night_no);
        } else {
            mPrePageImageView.setImageResource(R.drawable.btn_menu_pre_charpter_no);
            mNextPageImageView.setImageResource(R.drawable.btn_menu_next_charpter_no);
        }

        // changeJumpBackDefaultImage();
    }

    public void setJumpSeekBarEnable() {
        mJumpBar.setResopnseTouch(true);
        mJumpBarNight.setResopnseTouch(true);
        mJumpBar.setEnabled(true);
        mJumpBarNight.setEnabled(true);

        if (mSettings.isNightMode()) {
            mPrePageImageView.setImageResource(R.drawable.btn_menu_pre_charpter_night);
            mNextPageImageView.setImageResource(R.drawable.btn_menu_next_charpter_night);
        } else {
            mPrePageImageView.setImageResource(R.drawable.btn_menu_pre_charpter);
            mNextPageImageView.setImageResource(R.drawable.btn_menu_next_charpter);
        }

        // changeJumpBackEnable();
    }

    public BookContentMenuView(Context context) {
        this(context, null);
    }

    public BookContentMenuView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BookContentMenuView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.mActivity = (Activity) context;
    }

    /** 得到PageSettings对象 */
    public void setPageSettings(BookContentSettings mSettings) {
        this.mSettings = mSettings;
        init();
        setClickListener();
    }

    /** 设置点击中间区域监听 */
    public void setOnMenuEventListener(OnMenuEventListener onMenuEventListener) {
        this.mOnMenuEventListener = onMenuEventListener;
    }

    boolean isLoading;

    public void UnDayOrNight() {
        // mBottomMenuNightMode_tv.setEnabled(false);
        isLoading = true;
        changeJumpBackDefaultImage();
    }

    public void DayOrNight(boolean noEnable) {
        // mBottomMenuNightMode_tv.setEnabled(true);
        isLoading = false;
        if(!noEnable){
            changeJumpBackEnable();
        }
    }

    private void setClickListener() {
        mThemListView.setOnBorderListener(this);
        mThemeMoreImageView.setOnClickListener(this);
        mTheme0_relLayout.setOnClickListener(this);
        mTheme1_reLayout.setOnClickListener(this);
        mTheme2_reLayout.setOnClickListener(this);
        mTheme3_reLayout.setOnClickListener(this);
        mTheme4_reLayout.setOnClickListener(this);
        mTheme5_reLayout.setOnClickListener(this);
        mTheme6_reLayout.setOnClickListener(this);
        mTheme7_reLayout.setOnClickListener(this);

        mTextStyleDefault.setOnClickListener(this);
        mImageStyle1.setOnClickListener(this);
        mImageStyle2.setOnClickListener(this);
        mImageStyle3.setOnClickListener(this);

        mSystemBtn.setOnClickListener(this);// 系统调节亮度
        mTopMenuBack_view.setOnClickListener(this);
        mTopMenuShelf_view.setOnClickListener(this);
        mTopMenuCover_view.setOnClickListener(this);
        mChapterUrl_tv.setOnClickListener(this);// 来源

        findViewById(R.id.bookcontent_menu_gone).setOnClickListener(this);// 透明电极隐藏区域
        findViewById(R.id.bookcontent_menu_catalog).setOnClickListener(this);// 目录按钮
        mAddTextSizeImageView.setOnClickListener(this);// 增大字号按钮
        mReduceTextSizeImageView.setOnClickListener(this);// 减小字号按钮

        findViewById(R.id.bookcontent_menu_setting).setOnClickListener(this);// 设置
        findViewById(R.id.bookcontent_menu_nightmode).setOnClickListener(this);// 夜间模式
        mPrePageImageView.setOnClickListener(this);// 上一章
        mNextPageImageView.setOnClickListener(this);// 下一章
        findViewById(R.id.read_menu_progress_controller_no).setOnClickListener(this);
        findViewById(R.id.bookcontent_menu_moresetting).setOnClickListener(this);// 更多设置按钮
        findViewById(R.id.bookcontent_menu_moresetting1).setOnClickListener(this);// 更多设置按钮
        findViewById(R.id.bookcontent_menu_screen_lin).setOnClickListener(this);

        mJumpBar.setOnSeekBarChangeListener(this);
        mJumpBarNight.setOnSeekBarChangeListener(this);
        mLightBar.setOnSeekBarChangeListener(this);
        mNightLightBar.setOnSeekBarChangeListener(this);

        mBottomMenuNightMode_tv.setOnClickListener(this);
        mBottomMenuScreen_tv.setOnClickListener(this);
        mBottomMenuSetting_tv.setOnClickListener(this);
        mBottomMenuCatalog_tv.setOnClickListener(this);

        if (mOnMenuEventListener.getBookType() == Constant.BOOKTYPE_NET) {
            mTopMenuCover_view.setVisibility(View.GONE);
            mTopMenuCover_view.setVisibility(View.VISIBLE);
            mChapterUrl_tv.setText("");
            mTopMenuCover_view.setOnClickListener(this);// 顶部封面
        } else {
            mTopMenuCover_view.setVisibility(View.GONE);
        }

    }

    // 撤退，stop 跳转章节逻辑
    private void jumpByProgress(final float progress) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                mOnMenuEventListener.onJumpSeeked(progress < 0 ? 0 : progress);
            }
        }).start();

        StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_SEEKBAR);
    }

    // 显示百分比
    private void showHintText(float progress) {
        int type = mOnMenuEventListener.getBookType();
        progress *= 100;
        String strProgress = Constant.PERCENT_FORMAT.format(progress);
        strProgress = strProgress.equals("100.0") ? "100" : strProgress;
        if (type == Constant.BOOKTYPE_PAY || type == Constant.BOOKTYPE_ORDER_PAY
                || type == Constant.BOOKTYPE_NET) {
            // 付费书籍
            int total = mJumpBar.getMax();
            if (total > 0) {
                mHint1.setText(getResources().getString(R.string.bookcontentmenu_per_toast) + "  "
                        + strProgress + "%");
            }
        } else if (type == Constant.BOOKTYPE_EPUB || type == Constant.BOOKTYPE_BAG) {
            mHint1.setText(strProgress + "%");
        } else {
            // 本地书籍
            mHint1.setText(getResources().getString(R.string.bookcontentmenu_per_toast) + "  "
                    + strProgress + "%");
        }

    }

    // 显示百分比
    private String getHintProgress(float progress) {
        int type = mOnMenuEventListener.getBookType();
        progress *= 100;
        String strProgress = Constant.PERCENT_FORMAT.format(progress);
        strProgress = strProgress.equals("100.0") ? "100" : strProgress;
        if (type == Constant.BOOKTYPE_PAY || type == Constant.BOOKTYPE_ORDER_PAY
                || type == Constant.BOOKTYPE_NET) {
            // 付费书籍
            return (strProgress + "%");
        } else if (type == Constant.BOOKTYPE_EPUB || type == Constant.BOOKTYPE_BAG) {
            return (strProgress + "%");
        } else {
            // 本地书籍
            return (strProgress + "%");
        }

    }

    // TODO
    public void showCharpter(float progress, String str) {
        if (!("null").equals(str)) {
            mHint1.setText(str);
        }
        mHint2.setText(getHintProgress(progress));
    }

    /**
     * 调节字号
     * 
     * @remark 0,增大字号；1,减小字号
     */
    int mTextChange;

    private void adjustTextSize(int state) {
        mTextChange =
                mActivity.getResources()
                        .getDimensionPixelSize(R.dimen.bookcontent_text_size_change);
        if (state == 0) {// 增大字号
            mSettings.setTextSize(mSettings.getTextSize() + mTextChange, 1);
            // 是否可点
            if (mSettings.getTextSize() > BookContentSettings.BOOKCONTENT_TEXT_SIZE_MAX
                    - mTextChange) {
                if (mSettings.isNightMode()) {
                    mAddTextSizeImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.bg_word_change_big_press_night_no));
                } else {
                    mAddTextSizeImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.bg_word_change_big_press_no));
                }
            }
            // 回归减小为可点
            if (mSettings.getTextSize() > BookContentSettings.BOOKCONTENT_TEXT_SIZE_MIN) {
                if (mSettings.isNightMode()) {
                    mReduceTextSizeImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.bg_word_change_small_press_night));
                } else {
                    mReduceTextSizeImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.bg_word_change_small_press));
                }
            }
        } else if (state == 1) {// 减小字号
            mSettings.setTextSize(mSettings.getTextSize() - mTextChange, -1);

            // 是否可点
            if (mSettings.getTextSize() < BookContentSettings.BOOKCONTENT_TEXT_SIZE_MIN
                    + mTextChange) {
                if (mSettings.isNightMode()) {
                    mReduceTextSizeImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.bg_word_change_small_press_night_no));
                } else {
                    mReduceTextSizeImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.bg_word_change_small_press_no));
                }
            }
            // 回归增大为可点
            if (mSettings.getTextSize() < BookContentSettings.BOOKCONTENT_TEXT_SIZE_MAX) {
                if (mSettings.isNightMode()) {
                    mAddTextSizeImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.bg_word_change_big_press_night));
                } else {
                    mAddTextSizeImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.bg_word_change_big_press));
                }
            }
        }
    }

    /**
     * 点击夜间模式
     */
    private void clickNightMode() {
        mSettings.changeNightMode(true, false);
        changeLoadingTheme();
        // if (isLoading) {
        // mActivity.findViewById(R.id.time).setBackgroundColor(
        // Constant.READ_LOAD_COLORS[PayTheme.getCurrentTheme(mActivity)]);
        // }
        mOnMenuEventListener.onCloseMenu(false);// 阅读页可用
        setVisibility(View.GONE, true, mWhich);// 关闭菜单
        if (mSettings.isNightMode()) {
            Boolean isNoWarn =
                    SharedPreferenceUtil.getInstanceSharedPreferenceUtil()
                            .getBookContentNightModeNowarn();
            if (!isNoWarn) {
                showHintNightLightDialog();
            }
            setNightMenuMode();
        } else {
            setLightMmenuModel();
        }
        StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_MENU_NIGHT);// 统计
    }
    
    /**
     * 点击日夜间和主题切换，laoding也变
     */
    private void changeLoadingTheme(){
        if (isLoading) {
            int index = PayTheme.getCurrentTheme(mActivity);
            if (index == PayTheme.DEFAULT_THEME) {
                mActivity.findViewById(R.id.time).setBackgroundColor(0x000000);
                if (mSettings.getVertialScreen()) {
                    mActivity.findViewById(R.id.time).setBackgroundResource(R.drawable.ptheme1_background);
                } else {
                    mActivity.findViewById(R.id.time).setBackgroundResource(R.drawable.ptheme1_background1);
                }
            } else {
                mActivity.findViewById(R.id.time).setBackgroundDrawable(null);
                mActivity.findViewById(R.id.time).setBackgroundColor(Constant.READ_LOAD_COLORS[index]);
            }
        }
    }


    /** 显示提示调节夜间屏幕亮度dialog */
    private BottomDialogNight mNightHintLightDialog = null;
    private SeekBar mLightChangeSeekBar = null;
    private CheckBox mLightNoWarnCheckBox = null;
    private TextView mLightChangeOkTextView = null;

    /**
     * 亮度底部对话框
     */
    private void initNightModeDialog(View v) {
        mLightChangeSeekBar = (SeekBar) v.findViewById(R.id.light_change_seekbar);
        mLightNoWarnCheckBox = (CheckBox) v.findViewById(R.id.light_change_nowarn_checkbox);
        mLightChangeOkTextView = (TextView) v.findViewById(R.id.light_change_ok_tv);

        mLightNoWarnCheckBox.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // 软件退出设置false【重要】
                if (mLightNoWarnCheckBox.isChecked()) {
                    StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_NIGHT_OPEN);// 统计
                    SharedPreferenceUtil.getInstanceSharedPreferenceUtil()
                            .saveBookContentNightModeNowarn(true);
                } else {
                    StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_NIGHT_CLOSE);// 统计
                    SharedPreferenceUtil.getInstanceSharedPreferenceUtil()
                            .saveBookContentNightModeNowarn(false);
                }

            }
        });
        mLightChangeOkTextView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                SharedPreferenceUtil.getInstanceSharedPreferenceUtil()
                        .saveBookContentNightModeNowarn(true);
                mSettings.setLight(mLightChangeSeekBar.getProgress());
                mNightHintLightDialog.dismiss();
            }
        });
        mLightChangeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_NIGHT_SEEKBAR);// 统计
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                if (SharedPreferenceUtil.getInstanceSharedPreferenceUtil()
                        .getBookContentSystemButton()) {// 改变二级菜单亮度的状态
                    SharedPreferenceUtil.getInstanceSharedPreferenceUtil()
                            .saveBookContentSystemButton(false);
                    if (mSettings.isNightMode()) {// 设置菜单UI风格
                        setNightLightBar();
                    } else {
                        setDayLightBar();
                    }
                    // 对话框UI
                    // mLightChangeSeekBar.setProgressDrawable(getResources().getDrawable(
                    // R.drawable.seekbar_style_night));
                    // mLightChangeSeekBar.setThumb(getResources().getDrawable(
                    // R.drawable.progress_thumb_night));
                }
            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if (seekBar.getProgress() < 8) {
                    seekBar.setProgress(1);
                    mSettings.setLight(8);
                    return;
                }
                mSettings.setLight(mLightChangeSeekBar.getProgress());
            }
        });
    }

    /** 显示提示调节夜间亮度dialog */
    public void showHintNightLightDialog() {// TODO
        View view = View.inflate(mActivity, R.layout.view_nightmode_dialog, null);
        if (!mSettings.getVertialScreen()) {
            view = View.inflate(mActivity, R.layout.view_nightmode_horrizion_dialog, null);
        }
        mNightHintLightDialog = new BottomDialogNight(mActivity, view);
        initNightModeDialog(view);
        View v = (View) mNightHintLightDialog.findViewById(R.id.dialog_bottom_gone);
        v.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                SharedPreferenceUtil.getInstanceSharedPreferenceUtil()
                        .saveBookContentNightModeNowarn(true);
                mNightHintLightDialog.dismiss();
            }
        });
        int mLight = SharedPreferenceUtil.getInstanceSharedPreferenceUtil().getBookContentLight();
        mLightChangeSeekBar.setProgress(mLight);
        // if (!SharedPreferenceUtil.getInstanceSharedPreferenceUtil().getBookContentSystemButton())
        // {
        // mLightChangeSeekBar.setEnabled(true);
        // mLightChangeSeekBar.setProgressDrawable(getResources().getDrawable(
        // R.drawable.seekbar_style_night));
        // mLightChangeSeekBar.setThumb(getResources()
        // .getDrawable(R.drawable.progress_thumb_night));
        // } else {
        // mLightChangeSeekBar.setEnabled(false);
        // mLightChangeSeekBar.setProgressDrawable(getResources().getDrawable(
        // R.drawable.seekbar_style_night_system));
        // mLightChangeSeekBar.setThumb(getResources().getDrawable(
        // R.drawable.progress_thumb_night_system));
        // }

        mNightHintLightDialog.show();
    }


    private boolean isMenuEnable;

    public void setMenuEnable(boolean isMenuEnable) {
        this.isMenuEnable = isMenuEnable;
    }

    public boolean isMenuEnable() {
        return isMenuEnable;
    }

    /** 点击目录时禁止其他点击，防止目录与阅读页日夜间不匹配 */
    private void setMenuTabEnable(boolean enable) {
        findViewById(R.id.bookcontent_menu_nightmode).setEnabled(enable);
        findViewById(R.id.bookcontent_menu_catalog).setEnabled(enable);
        findViewById(R.id.bookcontent_menu_screen_lin).setEnabled(enable);
        findViewById(R.id.bookcontent_menu_setting).setEnabled(enable);
    }

    private void controllerJumpChapter(boolean isNext) {

        if (mOnMenuEventListener == null)
            return;

        if (mDoJumpChapterThread != null) {
            if (mDoJumpChapterThread.getRunning()) {
                return;
            } else {
                mDoJumpChapterThread = new JumpChapterThread(isNext);
            }
        } else {
            mDoJumpChapterThread = new JumpChapterThread(isNext);
        }

        mDoJumpChapterThread.start();
        changeJumpBackDefaultImage();
    }

    public class JumpChapterThread extends Thread {

        boolean mIsRunning = true;
        boolean mIsNext = false;

        JumpChapterThread(boolean isNext) {
            mIsNext = isNext;
        }

        @Override
        public void run() {
            super.run();
            mIsRunning = true;

            if (mIsNext) {
                mOnMenuEventListener.onJumpNextChapter();
            } else {
                mOnMenuEventListener.onJumpPrevChapter();
            }

            setJumpBarProgress();
            // mHint1.setText(((BookContentActivity) mActivity).mBookContentModel.mBookContentInfo
            // .getCurChapterName());
            mLastJumpProgress2 = -1;
            mIsRunning = false;
        }

        public boolean getRunning() {
            return mIsRunning;
        }
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bookcontent_menu_gone:
                mOnMenuEventListener.onCloseMenu(false);
                setVisibility(View.GONE, true, mWhich);
                setMenuEnable(false);
                break;
            case R.id.bookcontent_menu_catalog:// 跳转到目录
            case R.id.bc_menu_b1_catalogue_tv:
                setMenuTabEnable(false);
                setMenuEnable(false);
                mOnMenuEventListener.onCloseMenu(true);
                setVisibility(View.GONE, false, mWhich);// 关闭菜单
                // mOnMenuEventListener.onSetBookContentEnabled(false);
                mOnMenuEventListener.onNavigateToCatalog();
                break;
            case R.id.bookcontent_menu_textsize_add:// 增大字号
                adjustTextSize(0);
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_ADD_TEXTSIZE);
                break;
            case R.id.bookcontent_menu_textsize_reduce:// 减小字号
                adjustTextSize(1);
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_DECREASE_TEXTSIZE);
                break;
            case R.id.bookcontent_menu_prechapter:// 上一章
                dismissProgress();
                controllerJumpChapter(false);
                break;
            case R.id.bookcontent_menu_nextchapter:// 下一章
                dismissProgress();
                controllerJumpChapter(true);
                break;
            case R.id.bookcontent_menu_setting:// 设置
            case R.id.bc_menu_b1_setting_tv:
                setWordChangeState();
                setStyleState();
                setThemeItemUI(PayTheme.getCurrentTheme(mActivity));
                // setStyleItemUI(mSettings.getmStyle());
                mWhich = Constant.MENU_SECOND_LAYOUT;
                setVisibility(View.VISIBLE, true, mWhich);
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_SETTING);
                break;
            case R.id.bookcontent_menu_screen_lin:// 横竖屏
            case R.id.bookcontent_menu_screen_tv:
                mOnMenuEventListener.onCloseMenu(false);// 阅读页可用
                setVisibility(View.GONE, true, mWhich);// 关闭菜单

                ShuqiApplication.getApplicationHandler().postDelayed((new Runnable() {
                    public void run() {
                        mOnMenuEventListener.changeScreen();
                        mSettings.changeScreenWidthHeight();
                        mOnMenuEventListener.refreshBottomView();
                        if (mSettings.getVertialScreen()) {
                            setScreenVertical();
                            StatisticsUtils.onEvent(mActivity,
                                    StatisticsEventID.SCREEN_ORIENTATION_PORTRAIT);
                        } else {
                            setScreenHorizontal();
                            StatisticsUtils.onEvent(mActivity,
                                    StatisticsEventID.SCREEN_ORIENTATION_LANDSCAPE);
                        }
                    }
                }), 250);

                break;
            case R.id.bookcontent_menu_nightmode:// 夜间模式
            case R.id.bookcontent_menu_nightmode_tv:
                setMenuEnable(false);
                clickNightMode();
                break;
            case R.id.bookcontent_menu_lightsystem: {
                mSettings.setSystemLight();// 设置系统亮度和标志
                if (mSettings.isNightMode()) {// 设置UI风格
                    setNightLightBar();
                } else {
                    setDayLightBar();
                }
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_LIGHT_SYSTEM);
            }
                break;
            case R.id.bookcontent_menu_moresetting:// 更多设置
            case R.id.bookcontent_menu_moresetting1: {
                setMenuEnable(false);
                mOnMenuEventListener.onCloseMenu(false);
                setVisibility(View.GONE, true, mWhich);
                Intent intent = new Intent();
                intent.setClass(mActivity, BookContentMoreSetActivity.class);
                intent.putExtra("previewLineSpace", mSettings.getLineSpace());
                mActivity.startActivityForResult(intent,
                        BookContentActivity.REQUESTCODE_SET_SCREEN_FULL);
                mOnMenuEventListener.onSetBookContentEnabled(true);
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_MORESET);
            }
                break;
            case R.id.bookcontent_menu_top_back_view:// 返回
                if (mOnMenuEventListener != null) {
                    mOnMenuEventListener.onCloseMenu(false);
                    mOnMenuEventListener.onNavigateToBack();
                }
                break;
            case R.id.bookcontent_menu_top_shelf_view:// 顶部跳转到书架
                if (mOnMenuEventListener != null) {
                    mOnMenuEventListener.onCloseMenu(false);
                    mOnMenuEventListener.onNavigateToShelf();
                }
                break;
            case R.id.bookcontent_menu_top_cover_view:// 顶部跳转到封面
                if (mOnMenuEventListener != null) {
                    StatisticsUtils.onEvent(mActivity,
                            StatisticsEventID.BOOKCONTENT_SHENMA_ENTER_COVER);
                    mOnMenuEventListener.onCloseMenu(false);
                    mOnMenuEventListener.onNavigateToCover();
                }
                break;
            case R.id.tv_menutop_chaptersrc_url:
                if (mOnMenuEventListener != null) {
                    mOnMenuEventListener.onCloseMenu(false);
                    setVisibility(View.GONE, true, mWhich);
                    mOnMenuEventListener.onNavigateToSourceWeb();
                    StatisticsUtils.onEvent(mActivity,
                            StatisticsEventID.BOOKCONTENT_SHENMA_CLICK_COMEFROM);
                }

                break;
            case R.id.btn_menu_jump_back_img:// 撤销
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BACK_PROGRESS);
                if(mOnMenuEventListener.isLoading()){
                    Log4an.e("liyizhe", "lllllllllllllllllllllll");
                }
                if (mLastJumpProgress2 >= 0 && !mOnMenuEventListener.isLoading()) {
                    if (mOnMenuEventListener != null) {
                        // changeJumpBackImageDirection(!mIsFirstBack);
                        mIsFirstBack = !mIsFirstBack;
                        mJumpBar.setPercent(mLastJumpProgress1);
                        mJumpBarNight.setPercent(mLastJumpProgress1);
                        jumpByProgress(mLastJumpProgress1);

                        float temp = mLastJumpProgress2;
                        mLastJumpProgress2 = mLastJumpProgress1;
                        mLastJumpProgress1 = temp;

                        changeJumpBackDefaultImage();
                    }
                }
                break;
            case R.id.read_menu_progress_controller_no:// 未断章的
                ToastUtil.showToastFullyCustomizable(mActivity, "目录获取中，请稍候...");
                break;
            case R.id.theme_more: {// 主题箭头
                if (mIsThemeBottom) {
                    mThemListView.scrollToEnd();
                    // ((CustomHorizontalScrollView)
                    // findViewById(R.id.theme_scroll)).smoothScrollTo(
                    // findViewById(R.id.theme_scroll_layout).getWidth(), 0);

                    if (mSettings.isNightMode()) {
                        mThemeMoreImageView.setImageDrawable(getResources().getDrawable(
                                R.drawable.theme_more_night_left));
                    } else {
                        mThemeMoreImageView.setImageDrawable(getResources().getDrawable(
                                R.drawable.theme_more_left));
                    }

                    mIsThemeBottom = false;
                } else {
                    mThemListView.scrollToStart();
                    // ((CustomHorizontalScrollView)
                    // findViewById(R.id.theme_scroll)).smoothScrollTo(
                    // 0, 0);

                    if (mSettings.isNightMode()) {
                        mThemeMoreImageView.setImageDrawable(getResources().getDrawable(
                                R.drawable.theme_more_night_right));
                    } else {
                        mThemeMoreImageView.setImageDrawable(getResources().getDrawable(
                                R.drawable.theme_more_right));
                    }

                    mIsThemeBottom = true;
                }

                break;
            }

            case R.id.style_default:// 风格
                setStyleItem(0);
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_STYLE_DEFALUT);
                break;
            case R.id.style_1:
                setStyleItem(1);
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_STYLE_ONE);
                break;
            case R.id.style_2:
                setStyleItem(2);
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_STYLE_TWO);
                break;
            case R.id.style_3:
                setStyleItem(3);
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_STYLE_THREE);
                break;
            case R.id.layout_theme0:
                setThemeItem(0);
                break;
            case R.id.layout_theme1:
                setThemeItem(1);
                break;
            case R.id.layout_theme2:
                setThemeItem(2);
                break;
            case R.id.layout_theme3:
                setThemeItem(3);
                break;
            case R.id.layout_theme4:
                setThemeItem(4);
                break;
            case R.id.layout_theme5:
                setThemeItem(5);
                break;
            case R.id.layout_theme6:
                setThemeItem(6);
                break;
            case R.id.layout_theme7:
                setThemeItem(7);
                break;
        }
    }

    @Override
    public void onBottom() {
        if (mSettings.isNightMode()) {
            mThemeMoreImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.theme_more_night_left));
        } else {
            mThemeMoreImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.theme_more_left));
        }

        mIsThemeBottom = false;
    }

    @Override
    public void onTop() {
        if (mSettings.isNightMode()) {
            mThemeMoreImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.theme_more_night_right));
        } else {
            mThemeMoreImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.theme_more_right));
        }

        mIsThemeBottom = true;
    }

    /** 设置不同风格 */
    public void setStyleItem(int position) {
        if (position == mSettings.getmStyle()) {
            return;
        }
        mSettings.setStyle(position);
        setStyleItemUI(position);
    }

    private void setStyleItemUI(int position) {
        if (mSettings.isNightMode()) {
            mTextStyleDefault.setTextColor(0xff858585);
            mImageStyle1.setImageResource(R.drawable.menu_style_night_n1);
            mImageStyle2.setImageResource(R.drawable.menu_style_night_n2);
            mImageStyle3.setImageResource(R.drawable.menu_style_night_n3);
            switch (position) {
                case 0:
                    mTextStyleDefault.setTextColor(0xff156446);
                    break;
                case 1:
                    mImageStyle1.setImageResource(R.drawable.menu_style_night_p1);
                    break;
                case 2:
                    mImageStyle2.setImageResource(R.drawable.menu_style_night_p2);
                    break;
                case 3:
                    mImageStyle3.setImageResource(R.drawable.menu_style_night_p3);
                    break;
                default:
                    break;
            }
        } else {
            mTextStyleDefault.setTextColor(0xffefefef);
            mImageStyle1.setImageResource(R.drawable.menu_style_day_n1);
            mImageStyle2.setImageResource(R.drawable.menu_style_day_n2);
            mImageStyle3.setImageResource(R.drawable.menu_style_day_n3);
            switch (position) {
                case 0:
                    mTextStyleDefault.setTextColor(0xff14bb7b);
                    break;
                case 1:
                    mImageStyle1.setImageResource(R.drawable.menu_style_day_p1);
                    break;
                case 2:
                    mImageStyle2.setImageResource(R.drawable.menu_style_day_p2);
                    break;
                case 3:
                    mImageStyle3.setImageResource(R.drawable.menu_style_day_p3);
                    break;
                default:
                    break;
            }
        }
    }

    /** 设置不同主题 */
    public void setThemeItem(int position) {
        mOnMenuEventListener.onCloseMenu(false);// 阅读页可用
        setThemeItemUI(position);
        SharedPreferenceUtil.getInstanceSharedPreferenceUtil().saveBookContentTheme(position);
        mSettings.setTheme(position);
        changeLoadingTheme();
        // if (isLoading) {
        // mActivity.findViewById(R.id.time).setBackgroundColor(
        // Constant.READ_LOAD_COLORS[PayTheme.getCurrentTheme(mActivity)]);
        // }
        if (mSettings.isNightMode()) {//夜间模式的时候改为日间
            mSettings.changeNightMode(true, true); // 再将主题切换为非夜间模式
            setLightMmenuModel(); // 切换回非夜间的菜单
        }

        /* 主题模式，仅用于统计,(position+1)是按照界面上主题显示顺序 */
        setStatistics(position);
    }

    private void setThemeItemUI(int position) {
        mTheme0_img_bg.setVisibility(View.GONE);
        mTheme1_img_bg.setVisibility(View.GONE);
        mTheme2_img_bg.setVisibility(View.GONE);
        mTheme3_img_bg.setVisibility(View.GONE);
        mTheme4_img_bg.setVisibility(View.GONE);
        mTheme5_img_bg.setVisibility(View.GONE);
        mTheme6_img_bg.setVisibility(View.GONE);
        mTheme7_img_bg.setVisibility(View.GONE);
        switch (position) {
            case 0:
                mTheme0_img_bg.setVisibility(View.VISIBLE);
                break;
            case 1:
                mTheme1_img_bg.setVisibility(View.VISIBLE);
                break;
            case 2:
                mTheme2_img_bg.setVisibility(View.VISIBLE);
                break;
            case 3:
                mTheme3_img_bg.setVisibility(View.VISIBLE);
                break;
            case 4:
                mTheme4_img_bg.setVisibility(View.VISIBLE);
                break;
            case 5:
                mTheme5_img_bg.setVisibility(View.VISIBLE);
                break;
            case 6:
                mTheme6_img_bg.setVisibility(View.VISIBLE);
                break;
            case 7:
                mTheme7_img_bg.setVisibility(View.VISIBLE);
                break;
            case 8:
                setLastThemeItemUI(SharedPreferenceUtil.getInstanceSharedPreferenceUtil()
                        .getBookContentLastTheme());
                break;
            default:
                break;
        }
    }

    private void setLastThemeItemUI(int index) {
        switch (index) {
            case 0:
                mTheme0_img_bg.setVisibility(View.VISIBLE);
                break;
            case 1:
                mTheme1_img_bg.setVisibility(View.VISIBLE);
                break;
            case 2:
                mTheme2_img_bg.setVisibility(View.VISIBLE);
                break;
            case 3:
                mTheme3_img_bg.setVisibility(View.VISIBLE);
                break;
            case 4:
                mTheme4_img_bg.setVisibility(View.VISIBLE);
                break;
            case 5:
                mTheme5_img_bg.setVisibility(View.VISIBLE);
                break;
            case 6:
                mTheme6_img_bg.setVisibility(View.VISIBLE);
                break;
            case 7:
                mTheme7_img_bg.setVisibility(View.VISIBLE);
                break;
        }
    }

    public void setJumpBarProgress() {
        final float progress = (mOnMenuEventListener.onShowJumpSeekBar());
        mJumpBar.post(new Runnable() {
            @Override
            public void run() {
                mJumpBar.setPercent(progress);
                // showHintText(progress);
            }
        });
        mJumpBarNight.post(new Runnable() {
            @Override
            public void run() {
                mJumpBarNight.setPercent(progress);
                // showHintText(progress);
            }
        });
    }

    private void setStatistics(int position) {
        switch (position) {
            case 0:
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_THENE_ONE);
                break;
            case 1:
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_THENE_TWO);
                break;
            case 2:
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_THENE_THREE);
                break;
            case 3:
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_THENE_FORE);
                break;
            case 4:
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_THENE_FIVE);
                break;
            case 5:
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_THENE_SIX);
                break;
            case 6:
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_THENE_SEVEN);
                break;
            case 7:
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_THENE_EIGHT);
                break;
            default:
                break;
        }

    }

    private void setFullScreen(boolean enable) {
        if (enable) {
            mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
            RelativeLayout.LayoutParams params1 =
                    (android.widget.RelativeLayout.LayoutParams) mOnMenuEventListener.onGetView()
                            .getLayoutParams();
            params1.topMargin = 0;
            mOnMenuEventListener.onGetView().setLayoutParams(params1);
        } else {
            mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
            RelativeLayout.LayoutParams params1 =
                    (android.widget.RelativeLayout.LayoutParams) mOnMenuEventListener.onGetView()
                            .getLayoutParams();
            params1.topMargin = -mOnMenuEventListener.getBarHeight();
            mOnMenuEventListener.onGetView().setLayoutParams(params1);
        }
    }

    private boolean mIsFirstBack = true;

    /**
     * 设置日间亮度拖动条是否置灰
     */
    public void setDayLightBar() {
        mNightLightBar.setVisibility(View.GONE);
        mLightBar.setVisibility(View.VISIBLE);
        if (!SharedPreferenceUtil.getInstanceSharedPreferenceUtil().getBookContentSystemButton()) {
            mSystemBtn.setImageResource(R.drawable.unsystem_light);
            mSmallImageView.setImageResource(R.drawable.light_less);
            mBigImageView.setImageResource(R.drawable.light_bigger);
            // mLightBar.setEnabled(true);
            // mLightBar.setProgressDrawable(getResources().getDrawable(R.drawable.seekbar_style));
            // mLightBar.setThumb(getResources().getDrawable(R.drawable.progress_thumb));
        } else {
            mSystemBtn.setImageResource(R.drawable.system_light);
            mSmallImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.light_less_system));
            mBigImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.light_bigger_system));
            // mLightBar.setEnabled(false);
            // mLightBar.setProgressDrawable(getResources().getDrawable(
            // R.drawable.seekbar_style_system));
            // mLightBar.setThumb(getResources().getDrawable(R.drawable.progress_thumb_system));
        }
    }

    /**
     * 设置夜间亮度拖动条是否置灰
     */
    public void setNightLightBar() {
        mNightLightBar.setVisibility(View.VISIBLE);
        mLightBar.setVisibility(View.GONE);
        if (!SharedPreferenceUtil.getInstanceSharedPreferenceUtil().getBookContentSystemButton()) {
            mSystemBtn.setImageResource(R.drawable.unsystem_light_night);
            mSmallImageView.setImageResource(R.drawable.light_less_night);
            mBigImageView.setImageResource(R.drawable.light_bigger_night);
            // mNightLightBar.setEnabled(true);
            // mLightBar.setProgressDrawable(getResources()
            // .getDrawable(R.drawable.seekbar_style_night));
            // mLightBar.setThumb(getResources().getDrawable(R.drawable.progress_thumb_night));

        } else {
            mSystemBtn.setImageResource(R.drawable.system_light_night);
            mSmallImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.light_less_night_system));
            mBigImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.light_bigger_night_system));
            // mNightLightBar.setEnabled(false);

            // mLightBar.setProgressDrawable(getResources().getDrawable(
            // R.drawable.seekbar_style_night_system));
            // mLightBar.setThumb(getResources().getDrawable(R.drawable.progress_thumb_night_system));

        }
    }

    private void setOrderPayWordChangeState() {
        if (mSettings.isNightMode()) {
            mAddTextSizeImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.bg_word_change_big_press_night_no));
            mReduceTextSizeImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.bg_word_change_small_press_night_no));
        } else {
            mAddTextSizeImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.bg_word_change_big_press_no));
            mReduceTextSizeImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.bg_word_change_small_press_no));
        }
        mAddTextSizeImageView.setClickable(false);
        mReduceTextSizeImageView.setClickable(false);
    }

    /**
     * 判斷當前的字體
     */
    private void setWordChangeState() {
        mTextChange =
                mActivity.getResources()
                        .getDimensionPixelSize(R.dimen.bookcontent_text_size_change);
        // 设置字体调节的状态
        // if (mOnMenuEventListener.getBookType() == Constant.BOOKTYPE_ORDER_PAY) {
        // setOrderPayWordChangeState();
        // }
        if (mOnMenuEventListener.getCurReadState() != BookContentModel.READ_STATE_NORMAL) {
            setOrderPayWordChangeState();
        } else {
            mAddTextSizeImageView.setClickable(true);
            mReduceTextSizeImageView.setClickable(true);

            if (mSettings.isNightMode()) {
                mReduceTextSizeImageView.setImageDrawable(getResources().getDrawable(
                        R.drawable.bg_word_change_small_press_night));
                mAddTextSizeImageView.setImageDrawable(getResources().getDrawable(
                        R.drawable.bg_word_change_big_press_night));
            } else {
                mReduceTextSizeImageView.setImageDrawable(getResources().getDrawable(
                        R.drawable.bg_word_change_small_press));
                mAddTextSizeImageView.setImageDrawable(getResources().getDrawable(
                        R.drawable.bg_word_change_big_press));
            }
            if (mSettings.getTextSize() > BookContentSettings.BOOKCONTENT_TEXT_SIZE_MAX
                    - mTextChange) {
                if (mSettings.isNightMode()) {
                    mAddTextSizeImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.bg_word_change_big_press_night_no));
                } else {
                    mAddTextSizeImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.bg_word_change_big_press_no));
                }
            } else if (mSettings.getTextSize() < BookContentSettings.BOOKCONTENT_TEXT_SIZE_MIN
                    + mTextChange) {
                if (mSettings.isNightMode()) {
                    mReduceTextSizeImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.bg_word_change_small_press_night_no));
                } else {
                    mReduceTextSizeImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.bg_word_change_small_press_no));
                }
            }
        }
    }

    /**
     * 当前风格状态
     */
    private void setStyleState() {
        if (mOnMenuEventListener.getCurReadState() != BookContentModel.READ_STATE_NORMAL) {
            setOrderPayStyleState();
        } else {
            mTextStyleDefault.setClickable(true);
            mImageStyle1.setClickable(true);
            mImageStyle2.setClickable(true);
            mImageStyle3.setClickable(true);
            setStyleItemUI(mSettings.getmStyle());
        }
    }

    /**
     * 风格不可用状态
     */
    private void setOrderPayStyleState() {
        mTextStyleDefault.setClickable(false);
        mImageStyle1.setClickable(false);
        mImageStyle2.setClickable(false);
        mImageStyle3.setClickable(false);
        if (mSettings.isNightMode()) {
            mTextStyleDefault.setTextColor(0xff4d4d4d);
            mImageStyle1.setImageResource(R.drawable.menu_style_night_no1);
            mImageStyle2.setImageResource(R.drawable.menu_style_night_no2);
            mImageStyle3.setImageResource(R.drawable.menu_style_night_no3);
        } else {
            mTextStyleDefault.setTextColor(0xff7a7a7a);
            mImageStyle1.setImageResource(R.drawable.menu_style_no1);
            mImageStyle2.setImageResource(R.drawable.menu_style_no2);
            mImageStyle3.setImageResource(R.drawable.menu_style_no3);
        }
    }

    /** 横屏竖屏日间夜间 */
    private void setScreenIcon() {
        if (SharedPreferenceUtil.getInstanceSharedPreferenceUtil().getBookContentPortraitScreen()) {// 竖屏
            if (mSettings.isNightMode()) {// 夜间
                mBottomMenuScreen_tv
                        .setBackgroundResource(R.drawable.icon_menu_bottom_screen_heng_night_selector);
            } else {
                mBottomMenuScreen_tv
                        .setBackgroundResource(R.drawable.icon_menu_bottom_screen_heng_light_selector);
            }

        } else {// 横屏
            if (mSettings.isNightMode()) {// 夜间
                mBottomMenuScreen_tv
                        .setBackgroundResource(R.drawable.icon_menu_bottom_screen_shu_night_selector);
            } else {
                mBottomMenuScreen_tv
                        .setBackgroundResource(R.drawable.icon_menu_bottom_screen_shu_light_selector);
            }
        }
    }

    /** 断章是否结束 */
    public void IsCharpterOk() {
        // 未断章完成
        if (mOnMenuEventListener.getBookType() == Constant.BOOKTYPE_TXT
                && !SharedPreferenceUtil.getFileCatalogTool(mActivity,
                        mOnMenuEventListener.onTxtFilePath())) {
            findViewById(R.id.read_menu_progress_controller_no).setVisibility(View.VISIBLE);
            mJumpBar.setEnabled(false);
            mJumpBarNight.setEnabled(false);
            mPrePageImageView.setEnabled(false);
            mNextPageImageView.setEnabled(false);
            if (mSettings.isNightMode()) {
                // 上一章下一章按钮的显示颜色
                mPrePageImageView.setImageResource(R.drawable.btn_menu_pre_charpter_night_no);
                mNextPageImageView.setImageResource(R.drawable.btn_menu_next_charpter_night_no);
            } else {
                mPrePageImageView.setImageResource(R.drawable.btn_menu_pre_charpter_no);
                mNextPageImageView.setImageResource(R.drawable.btn_menu_next_charpter_no);
            }
        } else {
            findViewById(R.id.read_menu_progress_controller_no).setVisibility(View.GONE);
            mJumpBar.setEnabled(true);
            mJumpBarNight.setEnabled(true);
            mPrePageImageView.setEnabled(true);
            mNextPageImageView.setEnabled(true);
            if (mSettings.isNightMode()) {
                mPrePageImageView.setImageResource(R.drawable.btn_menu_pre_charpter_night);
                mNextPageImageView.setImageResource(R.drawable.btn_menu_next_charpter_night);
            } else {
                mPrePageImageView.setImageResource(R.drawable.btn_menu_pre_charpter);
                mNextPageImageView.setImageResource(R.drawable.btn_menu_next_charpter);
            }
        }
    }

    /** 判断有没有上一章或下一章，一级显示\点击上一章下一章\拖动条结束\调用 */
    // private void setPrevNextCharpter() {
    // setPrevEnable(mOnMenuEventListener.hasPreChapter());
    // setNextEnable(mOnMenuEventListener.hasNextChapter());
    // }

    /** 上一章是否可用 */
    @Deprecated
    private void setPrevEnable(boolean enable) {
        if (enable) {
            if (mSettings.isNightMode()) {
                mPrePageImageView.setEnabled(true);
            } else {
                mPrePageImageView.setEnabled(true);
            }
        } else {
            if (mSettings.isNightMode()) {
                mPrePageImageView.setEnabled(false);
            } else {
                mPrePageImageView.setEnabled(false);
            }
        }
    }

    /** 下一章是否可用 */
    @Deprecated
    private void setNextEnable(boolean enable) {
        if (enable) {
            if (mSettings.isNightMode()) {
                mNextPageImageView.setEnabled(true);
            } else {
                mNextPageImageView.setEnabled(true);
            }
        } else {
            if (mSettings.isNightMode()) {
                mNextPageImageView.setEnabled(false);
            } else {
                mNextPageImageView.setEnabled(false);
            }
        }
    }

    /** 初始化menuview */
    private void init() {
        setVisibility(View.GONE);
        LayoutInflater.from(mActivity).inflate(R.layout.view_bookcontent_menu, this);
        findByID();
    }

    private void findByID() {
        mBottomMenuLinearLayout = (LinearLayout) findViewById(R.id.menu_bottom);
        mBottomMenuProgressLayout = (LinearLayout) findViewById(R.id.menu_bottom_progress);
        mBottomMenuBottomLayout = (LinearLayout) findViewById(R.id.menu_bottom_bottom);
        mTopMenuLinearLayout = (LinearLayout) findViewById(R.id.bookcontent_menu_top_lin);
        mMoreSettingLinearLayout = (LinearLayout) findViewById(R.id.bookcontent_menu_bottom2);
        // mJumpLinearLayout = (LinearLayout) findViewById(R.id.bookcontentmenu_jump_lin);

        mJumpBar = (shuqiDefineSeekBar) findViewById(R.id.bookcontent_menu_jump_seekbar);
        mJumpBar.setMax(JUMPBAR_MAX_PROGRESS);
        mJumpBarNight = (shuqiDefineSeekBar) findViewById(R.id.bookcontent_menu_jump_seekbar_night);
        mJumpBarNight.setMax(JUMPBAR_MAX_PROGRESS);

        mHint1 = (TextView) findViewById(R.id.bookcontent_menu_hint1_tv);
        mHint2 = (TextView) findViewById(R.id.bookcontent_menu_hint2_tv);
        mJumpBackImageView = (ImageView) findViewById(R.id.btn_menu_jump_back_img);
        mJumpBackImageView.setOnClickListener(this);
        mLightBar = (SeekBar) findViewById(R.id.bookcontent_menu_jump_lightbar);
        mNightLightBar = (SeekBar) findViewById(R.id.bookcontent_menu_jump_lightbar_night);
        mThemeMoreImageView = (ImageView) findViewById(R.id.theme_more);
        mThemListView = (HorizontialListView) findViewById(R.id.bookcontent_menu_gallery);
        mSystemBtn = (ImageView) findViewById(R.id.bookcontent_menu_lightsystem);
        mSmallImageView = (ImageView) findViewById(R.id.light_small);
        mBigImageView = (ImageView) findViewById(R.id.light_big);
        mAddTextSizeImageView = (ImageView) findViewById(R.id.bookcontent_menu_textsize_add);
        mReduceTextSizeImageView = (ImageView) findViewById(R.id.bookcontent_menu_textsize_reduce);
        mPrePageImageView = (ImageView) findViewById(R.id.bookcontent_menu_prechapter);
        mNextPageImageView = (ImageView) findViewById(R.id.bookcontent_menu_nextchapter);

        mTheme0_relLayout = (RelativeLayout) findViewById(R.id.layout_theme0);
        mTheme1_reLayout = (RelativeLayout) findViewById(R.id.layout_theme1);
        mTheme2_reLayout = (RelativeLayout) findViewById(R.id.layout_theme2);
        mTheme3_reLayout = (RelativeLayout) findViewById(R.id.layout_theme3);
        mTheme4_reLayout = (RelativeLayout) findViewById(R.id.layout_theme4);
        mTheme5_reLayout = (RelativeLayout) findViewById(R.id.layout_theme5);
        mTheme6_reLayout = (RelativeLayout) findViewById(R.id.layout_theme6);
        mTheme7_reLayout = (RelativeLayout) findViewById(R.id.layout_theme7);
        mTheme0_img = (ImageView) findViewById(R.id.theme0);
        mTheme1_img = (ImageView) findViewById(R.id.theme1);
        mTheme2_img = (ImageView) findViewById(R.id.theme2);
        mTheme3_img = (ImageView) findViewById(R.id.theme3);
        mTheme4_img = (ImageView) findViewById(R.id.theme4);
        mTheme5_img = (ImageView) findViewById(R.id.theme5);
        mTheme6_img = (ImageView) findViewById(R.id.theme6);
        mTheme7_img = (ImageView) findViewById(R.id.theme7);
        mTheme0_img_bg = (ImageView) findViewById(R.id.bg_theme0);
        mTheme1_img_bg = (ImageView) findViewById(R.id.bg_theme1);
        mTheme2_img_bg = (ImageView) findViewById(R.id.bg_theme2);
        mTheme3_img_bg = (ImageView) findViewById(R.id.bg_theme3);
        mTheme4_img_bg = (ImageView) findViewById(R.id.bg_theme4);
        mTheme5_img_bg = (ImageView) findViewById(R.id.bg_theme5);
        mTheme6_img_bg = (ImageView) findViewById(R.id.bg_theme6);
        mTheme7_img_bg = (ImageView) findViewById(R.id.bg_theme7);

        mTextStyleDefault = (TextView) findViewById(R.id.style_default);
        mImageStyle1 = (ImageView) findViewById(R.id.style_1);
        mImageStyle2 = (ImageView) findViewById(R.id.style_2);
        mImageStyle3 = (ImageView) findViewById(R.id.style_3);

        mThemeAdapter = new PayBcMenuThemAdapter(mActivity, mSettings, this);
        if (mSettings.isNightMode()) {
            mThemeAdapter.setNightMode(true);
        } else {
            mThemeAdapter.setNightMode(false);
        }
        mThemListView.setAdapter(mThemeAdapter);
        mThemListView.setOnItemClickListener(this);
        mThemListView.setSelection(mSettings.getTheme());

        mBottomMenuNightMode_tv = (TextView) findViewById(R.id.bookcontent_menu_nightmode_tv);
        mBottomMenuScreen_tv = (TextView) findViewById(R.id.bookcontent_menu_screen_tv);
        mBottomMenuSetting_tv = (TextView) findViewById(R.id.bc_menu_b1_setting_tv);
        mBottomMenuCatalog_tv = (TextView) findViewById(R.id.bc_menu_b1_catalogue_tv);

        mTopMenuBack_view = (View) findViewById(R.id.bookcontent_menu_top_back_view);
        mTopMenuShelf_view = (View) findViewById(R.id.bookcontent_menu_top_shelf_view);
        mTopMenuCover_view = (View) findViewById(R.id.bookcontent_menu_top_cover_view);
        mChapterUrl_tv = (TextView) findViewById(R.id.tv_menutop_chaptersrc_url);
    }

    /** 点击中间区域监听回调接口 */
    public interface OnMenuEventListener {
        /**
         * 获取当前阅读页状态是否是正文
         */
        public int getCurReadState();

        /**
         * 刷新bottomView
         */
        public void refreshBottomView();

        /** 显示对应进度章节名 */
        public void showChapterName(float progress);

        /** 切换横竖屏 */
        public void changeScreen();

        /** 是否存在上一章 */
        public boolean hasPreChapter();

        /** 是否存在下一章 */
        public boolean hasNextChapter();

        /** 关闭菜单(动画) */
        public void onCloseMenu(boolean isAnimation);

        /** 获取当前的进度跳进度 */
        public float onShowJumpSeekBar();

        /** 进度条跳转进度 */
        public void onJumpSeeked(float progress);

        /** 跳转到上一章 */
        public void onJumpPrevChapter();

        /** 跳转到下一章 */
        public void onJumpNextChapter();

        /** 跳转到目录 */
        public void onNavigateToCatalog();

        /** 跳转到封面 */
        public void onNavigateToCover();

        /** 跳转到书架 */
        public void onNavigateToShelf();

        /** 返回 */
        public void onNavigateToBack();

        /** 网页打开来源地址 */
        public void onNavigateToSourceWeb();

        /** 获取屏幕亮度 */
        public int onScreenLight();

        /** 获取阅读页书籍类型 */
        public int getBookType();

        /** 获取绘制是否可点击 */
        public boolean isBookContentEnabled();

        /** 设置阅读页是否可用 */
        public void onSetBookContentEnabled(boolean isEnable);

        /** 阅读页绘制view */
        public View onGetView();

        /** 获取设备顶部导航高度 */
        public int getBarHeight();

        public boolean isLoading();

        /** 获取txt阅读文件路径 */
        public String onTxtFilePath();

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        // 底部基本菜单
        // if (parent.getId() == R.id.bookcontent_menu_gallery) {
        // ((BaseAdapter) parent.getAdapter()).notifyDataSetChanged();
        // SharedPreferenceUtil.getInstanceSharedPreferenceUtil().saveBookContentTheme(position);
        // mSettings.setTheme(position);
        // mSettings.changeNightMode(false, true); // 再将主题切换为非夜间模式
        // setLightMmenuModel(); // 切换回非夜间的菜单
        //
        // /* 主题模式，仅用于统计,(position+1)是按照界面上主题显示顺序 */
        // HashMap<String, String> themMap = new HashMap<String, String>();
        // themMap.put("theme", "" + (position + 1));
        // StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_THEME, themMap);
        // if (themMap != null && themMap.size() > 0) {
        // themMap.clear();
        // themMap = null;
        // }
        // }

        if (parent.getId() == R.id.bookcontent_menu_gallery) {
            mOnMenuEventListener.onCloseMenu(false);// 阅读页可用
            ((BaseAdapter) parent.getAdapter()).notifyDataSetChanged();
            SharedPreferenceUtil.getInstanceSharedPreferenceUtil().saveBookContentTheme(position);
            mSettings.setTheme(position);
            changeLoadingTheme();
            // if (isLoading) {
            // mActivity.findViewById(R.id.time).setBackgroundColor(
            // Constant.READ_LOAD_COLORS[PayTheme.getCurrentTheme(mActivity)]);
            // }
            if (mSettings.isNightMode()) {
                mSettings.changeNightMode(true, true); // 再将主题切换为非夜间模式
                setLightMmenuModel(); // 切换回非夜间的菜单
            }

            /* 主题模式，仅用于统计,(position+1)是按照界面上主题显示顺序 */
            setStatistics(position);
        }
    }


    /**
     * 设置菜单隐藏/显示，并进行相应操作
     * 
     * @param visibility
     * @param isAnimation 动画
     */
    public void setVisibility(int visibility, boolean isAnimation, int which) {
        // mHandler.removeMessages(0);
        if (mTopInAnimation == null) {
            mTopInAnimation = AnimationUtils.loadAnimation(mActivity, R.anim.menu_push_bottom_in);
        }
        if (mTopOutAnimation == null) {
            mTopOutAnimation = AnimationUtils.loadAnimation(mActivity, R.anim.menu_push_bottom_out);
        }
        if (mBottomInAnimation == null) {
            mBottomInAnimation = AnimationUtils.loadAnimation(mActivity, R.anim.menu_push_top_in);
        }
        if (mBottomOutAnimation == null) {
            mBottomOutAnimation = AnimationUtils.loadAnimation(mActivity, R.anim.menu_push_top_out);
        }
        // 设置横竖屏显示/隐藏的元素
        switch (visibility) {
            case View.VISIBLE:
                mHandler.removeMessages(0);
                setMenuTabEnable(true);

                setChildVisibility(which);
                super.setVisibility(View.VISIBLE);
                if (which == Constant.MENU_FIRST_LAYOUT && isAnimation) {
                    if (SharedPreferenceUtil.getInstanceSharedPreferenceUtil()
                            .getBookContentFullScreen()) {
                        setFullScreen(false);
                    }
                    mTopMenuLinearLayout.startAnimation(mTopInAnimation);
                    mBottomMenuLinearLayout.startAnimation(mBottomInAnimation);

                } else if (which == Constant.MENU_SECOND_LAYOUT && isAnimation) {
                    if (SharedPreferenceUtil.getInstanceSharedPreferenceUtil()
                            .getBookContentFullScreen()) {
                        setFullScreen(true);
                    }
                    mTopMenuLinearLayout.startAnimation(mTopOutAnimation);
                    mMoreSettingLinearLayout.startAnimation(mBottomOutAnimation);
                    mMoreSettingLinearLayout.startAnimation(mBottomInAnimation);
                }

                if (mOnMenuEventListener != null) {
                    if (which == Constant.MENU_SECOND_LAYOUT) {
                        int lightProgress = mOnMenuEventListener.onScreenLight();
                        if (lightProgress <= 8) {
                            mLightBar.setProgress(1);
                            mNightLightBar.setProgress(1);
                        } else {
                            mLightBar.setProgress(lightProgress);
                            mNightLightBar.setProgress(lightProgress);
                        }

                    } else if (which == Constant.MENU_FIRST_LAYOUT) {
                        // 断章结束判断
                        IsCharpterOk();

                        // 进度
                        float progress = mOnMenuEventListener.onShowJumpSeekBar();
                        if (progress > mJumpBar.getMax()) {
                            progress = mJumpBar.getMax();
                        }
                        if (progress >= 0) {
                            showHintText(progress);
                            mJumpBar.setPercent(progress);
                            mJumpBarNight.setPercent(progress);
                            mLastJumpProgress1 = progress;
                        }
                        mLastJumpProgress2 = -1;

                        // 消失进度，消失消息
                        dismissProgress();

                        // 上一章下一章有没有
                    }
                }

                break;
            case View.GONE:
                if (mHandler.hasMessages(0)) {
                    break;
                }
                mHandler.removeMessages(0);
                if (which == Constant.MENU_FIRST_LAYOUT && isAnimation) {
                    mTopMenuLinearLayout.startAnimation(mTopOutAnimation);
                    mBottomMenuLinearLayout.startAnimation(mBottomOutAnimation);
                    mBottomOutAnimation.setDuration(mDuration);
                } else if (which == Constant.MENU_SECOND_LAYOUT && isAnimation) {
                    mMoreSettingLinearLayout.startAnimation(mBottomOutAnimation);
                    mBottomOutAnimation.setDuration(mDuration);
                }
                mHandler.sendEmptyMessageDelayed(MENU_MSG_GONE, mDuration);
                break;
        }
    }

    /**
     * 设置显示哪个子菜单 参数：0 ：默认
     * 
     * @param which
     */
    private void setChildVisibility(int which) {
        mTopMenuLinearLayout.setVisibility(which == Constant.MENU_FIRST_LAYOUT ? View.VISIBLE
                : View.GONE);
        mBottomMenuLinearLayout.setVisibility(which == Constant.MENU_FIRST_LAYOUT ? View.VISIBLE
                : View.GONE);
        mMoreSettingLinearLayout.setVisibility(which == Constant.MENU_SECOND_LAYOUT ? View.VISIBLE
                : View.GONE);
    }

    /** 显示提示章节名 */
    public void showToastChapterName(String content) {
        mHandler.sendEmptyMessageDelayed(1, 2000);
    }

    /** 跳章时更新当前章节百分比 */
    public void updatePercentOnJump(int progress) {

    }

    /** 阅读页加载完成更新菜单 */
    public void onBookContentComplete() {
        if (mOnMenuEventListener != null && !mJumpBar.isEnabled()) {
            mJumpBar.setEnabled(true);

        }
        if (mOnMenuEventListener != null && !mJumpBar.isEnabled()) {
            mJumpBar.setEnabled(true);
            // 初始化章节进度跳转
            float progress = mOnMenuEventListener.onShowJumpSeekBar();
            if (progress > 1f) {
                progress = 1;
            }
            if (progress >= 0) {
                showHintText(progress);
                mLastJumpProgress1 = progress;
                mJumpBar.setPercent(progress);
                mJumpBarNight.setPercent(progress);
            }
            mLastJumpProgress2 = -1;
        }
    }

    /** 撤销不可用 */
    private void changeJumpBackDefaultImage() {
        mJumpBackImageView.setEnabled(false);
        if (mSettings.isNightMode()) {
            mJumpBackImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.btn_menu_jumb_back_night_default));
        } else {
            mJumpBackImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.btn_menu_jumb_back_default));
        }
    }

    /** 撤销可用 */
    private void changeJumpBackEnable() {
        mJumpBackImageView.setEnabled(true);
        if (mSettings.isNightMode()) {
            mJumpBackImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.btn_menu_jump_back_night_left));
        } else {
            mJumpBackImageView.setImageDrawable(getResources().getDrawable(
                    R.drawable.btn_menu_jump_back_left));
        }
    }


    /**
     * 改变撤销图片状态
     * 
     * @param isChange
     * @param isFirst
     */
    private void changeJumpBackImage(boolean isChange, boolean isFirst) {
        if (mSettings.isNightMode()) {
            if (isChange) {
                if (isFirst) {
                    mJumpBackImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.btn_menu_jump_back_night_left));
                } else {
                    mJumpBackImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.btn_menu_jump_back_night_right));
                }
            } else {
                changeJumpBackDefaultImage();
            }
        } else {
            if (isChange) {
                if (isFirst) {
                    mJumpBackImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.btn_menu_jump_back_left));
                } else {
                    mJumpBackImageView.setImageDrawable(getResources().getDrawable(
                            R.drawable.btn_menu_jump_back_right));
                }
            } else {
                changeJumpBackDefaultImage();
            }
        }
    }

    /**
     * 改变跳转图片方向
     * 
     * @param isDirection
     */
    private void changeJumpBackImageDirection(boolean isDirection) {
        if (mSettings.isNightMode()) {
            if (isDirection) {// 左
                mJumpBackImageView.setImageDrawable(getResources().getDrawable(
                        R.drawable.btn_menu_jump_back_night_left));
            } else {// 右
                mJumpBackImageView.setImageDrawable(getResources().getDrawable(
                        R.drawable.btn_menu_jump_back_night_right));
            }
        } else {
            if (isDirection) {// 左
                mJumpBackImageView.setImageDrawable(getResources().getDrawable(
                        R.drawable.btn_menu_jump_back_left));
            } else {// 右
                mJumpBackImageView.setImageDrawable(getResources().getDrawable(
                        R.drawable.btn_menu_jump_back_right));
            }
        }
    }


    /** 更换为竖屏模式 */
    public void setScreenVertical() {
        // 进度的宽度
        LinearLayout.LayoutParams mLayoutParams =
                (LinearLayout.LayoutParams) mBottomMenuProgressLayout.getLayoutParams();
        mLayoutParams.leftMargin = Util.dip2px(mActivity, 28);
        mLayoutParams.rightMargin = Util.dip2px(mActivity, 28);
        mBottomMenuProgressLayout.setLayoutParams(mLayoutParams);
        // 横竖屏icon
        setScreenIcon();
        // 更多设置
        ((ImageView) findViewById(R.id.line7)).setVisibility(View.GONE);
        ((ImageView) findViewById(R.id.line6)).setVisibility(View.VISIBLE);
        ((TextView) findViewById(R.id.bookcontent_menu_moresetting1)).setVisibility(View.GONE);
        ((TextView) findViewById(R.id.bookcontent_menu_moresetting)).setVisibility(View.VISIBLE);
        // 主题
        findViewById(R.id.theme_layout_list).setVisibility(View.VISIBLE);
        findViewById(R.id.theme_layout_iv).setVisibility(View.GONE);
    }

    /** 更换为横屏模式 */
    public void setScreenHorizontal() {
        // 进度的宽度
        LinearLayout.LayoutParams mLayoutParams =
                (LinearLayout.LayoutParams) mBottomMenuProgressLayout.getLayoutParams();
        mLayoutParams.leftMargin = Util.dip2px(mActivity, 100);
        mLayoutParams.rightMargin = Util.dip2px(mActivity, 100);
        mBottomMenuProgressLayout.setLayoutParams(mLayoutParams);
        // 横竖屏icon
        setScreenIcon();
        // 跟多设置
        ((ImageView) findViewById(R.id.line7)).setVisibility(View.VISIBLE);
        ((ImageView) findViewById(R.id.line6)).setVisibility(View.GONE);
        ((TextView) findViewById(R.id.bookcontent_menu_moresetting1)).setVisibility(View.VISIBLE);
        ((TextView) findViewById(R.id.bookcontent_menu_moresetting)).setVisibility(View.GONE);
        // 主题
        findViewById(R.id.theme_layout_list).setVisibility(View.GONE);
        findViewById(R.id.theme_layout_iv).setVisibility(View.VISIBLE);
    }

    /** 更换夜间模式菜单图标 */
    public void setNightMenuMode() {
        mBottomMenuBottomLayout.setBackgroundColor(0xf23a3a3a);
        mTopMenuLinearLayout.setBackgroundColor(0xf23a3a3a);
        mMoreSettingLinearLayout.setBackgroundColor(0xf23a3a3a);
        mBottomMenuProgressLayout.setBackgroundResource(R.drawable.menu_prograss_dismiss_night);

        // 一级下菜单
        changeJumpBackImage(false, false);
        mHint1.setTextColor(0xff858585);
        mHint2.setTextColor(0xff858585);
        ((ImageView) findViewById(R.id.view_left_line)).setBackgroundColor(0xff434343);
        mPrePageImageView.setImageResource(R.drawable.btn_menu_pre_charpter_night);
        mNextPageImageView.setImageResource(R.drawable.btn_menu_next_charpter_night);
        mJumpBar.setVisibility(View.GONE);
        mJumpBarNight.setVisibility(View.VISIBLE);
        ((ImageView) findViewById(R.id.view_bottom_line)).setBackgroundColor(0xff434343);

        mBottomMenuNightMode_tv.setBackgroundResource(R.drawable.icon_menu_bottom3_light_selector);
        mBottomMenuSetting_tv.setBackgroundResource(R.drawable.icon_menu_bottom_night_selector);
        setScreenIcon();
        mBottomMenuCatalog_tv.setBackgroundResource(R.drawable.btn_menu_middle_light_selector);

        // 一级上菜单
        mChapterUrl_tv.setTextColor(getResources().getColorStateList(
                R.drawable.textcolor_reader_menu_night_selector));
        mTopMenuBack_view.setBackgroundResource(R.drawable.icon_bookcontent_night_back_selector);
        mTopMenuShelf_view.setBackgroundResource(R.drawable.icon_bookcontent_night_shelf_selector);
        mTopMenuCover_view.setBackgroundResource(R.drawable.icon_bookcontent_night_cover_selector);

        // 二级菜单
        ((ImageView) findViewById(R.id.line2)).setBackgroundColor(0xff434343);
        ((ImageView) findViewById(R.id.line3)).setBackgroundColor(0xff434343);
        ((ImageView) findViewById(R.id.line4)).setBackgroundColor(0xff434343);
        ((ImageView) findViewById(R.id.line5)).setBackgroundColor(0xff434343);
        ((ImageView) findViewById(R.id.line6)).setBackgroundColor(0xff434343);
        ((ImageView) findViewById(R.id.line7)).setBackgroundColor(0xff434343);
        setNightLightBar();
        setWordChangeState();
        setStyleState();
        // setStyleItemUI(mSettings.getmStyle());
        ((TextView) findViewById(R.id.bookcontent_menu_moresetting)).setTextColor(getResources()
                .getColorStateList(R.drawable.textcolor_reader_menu_night_selector));
        ((TextView) findViewById(R.id.bookcontent_menu_moresetting1)).setTextColor(getResources()
                .getColorStateList(R.drawable.textcolor_reader_menu_night_selector));

        // theme
        if (mThemeAdapter != null) {
            mThemeAdapter.setNightMode(true);
            mThemeAdapter.notifyDataSetChanged();
        }
        mTheme0_img.setImageResource(R.drawable.icon_them_night0);
        mTheme1_img.setImageResource(R.drawable.icon_them_night1);
        mTheme2_img.setImageResource(R.drawable.icon_them_night2);
        mTheme3_img.setImageResource(R.drawable.icon_them_night3);
        mTheme4_img.setImageResource(R.drawable.icon_them_night4);
        mTheme5_img.setImageResource(R.drawable.icon_them_night5);
        mTheme6_img.setImageResource(R.drawable.icon_them_night6);
        mTheme7_img.setImageResource(R.drawable.icon_them_night7);
        mTheme0_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box_night);
        mTheme1_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box_night);
        mTheme2_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box_night);
        mTheme3_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box_night);
        mTheme4_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box_night);
        mTheme5_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box_night);
        mTheme6_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box_night);
        mTheme7_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box_night);

    }

    /** 更换日间模式菜单图标 */
    public void setLightMmenuModel() {
        mBottomMenuBottomLayout.setBackgroundColor(0xf7353535);
        mTopMenuLinearLayout.setBackgroundColor(0xf7353535);
        mMoreSettingLinearLayout.setBackgroundColor(0xf7353535);
        mBottomMenuProgressLayout.setBackgroundResource(R.drawable.menu_prograss_dismiss_day);

        // 一级下菜单
        changeJumpBackImage(false, false);
        mHint1.setTextColor(0xffd4d4d4);
        mHint2.setTextColor(0xffd4d4d4);
        ((ImageView) findViewById(R.id.view_left_line)).setBackgroundColor(0xff585858);
        mPrePageImageView.setImageResource(R.drawable.btn_menu_pre_charpter);
        mNextPageImageView.setImageResource(R.drawable.btn_menu_next_charpter);
        mJumpBar.setVisibility(View.VISIBLE);
        mJumpBarNight.setVisibility(View.GONE);
        ((ImageView) findViewById(R.id.view_bottom_line)).setBackgroundColor(0xff585858);

        mBottomMenuNightMode_tv.setBackgroundResource(R.drawable.icon_menu_bottom3_night_selector);
        mBottomMenuSetting_tv.setBackgroundResource(R.drawable.icon_menu_bottom_selector);
        setScreenIcon();
        mBottomMenuCatalog_tv.setBackgroundResource(R.drawable.btn_menu_middle_selector);

        // 一级上菜单
        mChapterUrl_tv.setTextColor(getResources().getColorStateList(
                R.drawable.textcolor_reader_menu_selector));
        mTopMenuBack_view.setBackgroundResource(R.drawable.icon_bookcontent_back_selector);
        mTopMenuShelf_view.setBackgroundResource(R.drawable.icon_bookcontent_shelf_selector);
        mTopMenuCover_view.setBackgroundResource(R.drawable.icon_bookcontent_cover_selector);

        // 二级菜单
        ((ImageView) findViewById(R.id.line2)).setBackgroundColor(0xff585858);
        ((ImageView) findViewById(R.id.line3)).setBackgroundColor(0xff585858);
        ((ImageView) findViewById(R.id.line4)).setBackgroundColor(0xff585858);
        ((ImageView) findViewById(R.id.line5)).setBackgroundColor(0xff585858);
        ((ImageView) findViewById(R.id.line6)).setBackgroundColor(0xff585858);
        ((ImageView) findViewById(R.id.line7)).setBackgroundColor(0xff585858);
        setDayLightBar();
        setWordChangeState();
        setStyleState();
        // setStyleItemUI(mSettings.getmStyle());
        ((TextView) findViewById(R.id.bookcontent_menu_moresetting)).setTextColor(getResources()
                .getColorStateList(R.drawable.textcolor_reader_menu_selector));
        ((TextView) findViewById(R.id.bookcontent_menu_moresetting1)).setTextColor(getResources()
                .getColorStateList(R.drawable.textcolor_reader_menu_selector));

        // theme
        if (mThemeAdapter != null) {
            mThemeAdapter.setNightMode(false);
            mThemeAdapter.notifyDataSetChanged();
        }
        mTheme0_img.setImageResource(R.drawable.icon_them0);
        mTheme1_img.setImageResource(R.drawable.icon_them1);
        mTheme2_img.setImageResource(R.drawable.icon_them2);
        mTheme3_img.setImageResource(R.drawable.icon_them3);
        mTheme4_img.setImageResource(R.drawable.icon_them4);
        mTheme5_img.setImageResource(R.drawable.icon_them5);
        mTheme6_img.setImageResource(R.drawable.icon_them6);
        mTheme7_img.setImageResource(R.drawable.icon_them7);
        mTheme0_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box);
        mTheme1_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box);
        mTheme2_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box);
        mTheme3_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box);
        mTheme4_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box);
        mTheme5_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box);
        mTheme6_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box);
        mTheme7_img_bg.setImageResource(R.drawable.p_bg_menu_theme_box);

    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        switch (seekBar.getId()) {
            case R.id.bookcontent_menu_jump_seekbar:
            case R.id.bookcontent_menu_jump_seekbar_night: {// 跳转进度
                // mBottomMenuProgressLayout.setVisibility(View.VISIBLE);
                shuqiDefineSeekBar jumpBar = (shuqiDefineSeekBar) seekBar;
                mOnMenuEventListener.showChapterName(jumpBar.getPercent());
            }
                break;
            case R.id.bookcontent_menu_jump_lightbar:
            case R.id.bookcontent_menu_jump_lightbar_night: {// 设置中亮度
                if (seekBar.getProgress() < 8) {
                    seekBar.setProgress(1);
                    mSettings.setLight(8);
                    return;
                }
                mLightBar.setProgress(seekBar.getProgress());
                mNightLightBar.setProgress(seekBar.getProgress());
                mSettings.setLight(seekBar.getProgress());
            }
                break;
        }
    }


    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        onStopPropressTouch(seekBar);
    }

    private void onStopPropressTouch(SeekBar seekBar) {

        switch (seekBar.getId()) {
            case R.id.bookcontent_menu_jump_seekbar:
            case R.id.bookcontent_menu_jump_seekbar_night: {// 跳转进度
                mHandler.sendEmptyMessageDelayed(MENU_MSG_PROGRESS_GONE, 2000);// 两秒消失
                // mHandler.removeMessages(MENU_MSG_PROGRESS_GONE);
                if (mOnMenuEventListener != null) {
                    shuqiDefineSeekBar jumpBar = (shuqiDefineSeekBar) seekBar;
                    float progress = jumpBar.getPercent();// 进度获取
                    mOnMenuEventListener.showChapterName(progress);// 章节名
                    jumpByProgress(progress);// 进度跳转

                    if (initBack) {
                        // 如果进度没变，则撤销致灰不可用
                        if (mLastJumpProgress2 != progress) {
                            changeJumpBackEnable();
                            if (mLastJumpProgress2 < 0) {
                                mLastJumpProgress2 = progress;
                            } else {
                                mLastJumpProgress1 = mLastJumpProgress2;
                                mLastJumpProgress2 = progress;
                            }
                        } else {
                            changeJumpBackDefaultImage();
                        }
                        initBack = false;
                        // changeJumpBackImage(true, mIsFirstBack);
                    } else {
                        // 如果进度每消失时，点击相同进度，则按照没点处理
                        if (progress != mLastJumpProgress2) {
                            changeJumpBackEnable();
                            if (mLastJumpProgress2 < 0) {
                                mLastJumpProgress2 = progress;
                            } else {
                                mLastJumpProgress1 = mLastJumpProgress2;
                                mLastJumpProgress2 = progress;
                            }
                        }

                    }
                }
            }
                break;
            case R.id.bookcontent_menu_jump_lightbar:
            case R.id.bookcontent_menu_jump_lightbar_night: {// 设置中亮度
                StatisticsUtils.onEvent(mActivity, StatisticsEventID.BOOKCONTENT_LIGHT_SEEKBAR);
            }
                break;
        }

    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        switch (seekBar.getId()) {
            case R.id.bookcontent_menu_jump_lightbar_night:
            case R.id.bookcontent_menu_jump_lightbar:
                if (SharedPreferenceUtil.getInstanceSharedPreferenceUtil()
                        .getBookContentSystemButton()) {
                    SharedPreferenceUtil.getInstanceSharedPreferenceUtil()
                            .saveBookContentSystemButton(false);
                    if (mSettings.isNightMode()) {// 设置UI风格
                        setNightLightBar();
                    } else {
                        setDayLightBar();
                    }
                }
                break;
            case R.id.bookcontent_menu_jump_seekbar:
            case R.id.bookcontent_menu_jump_seekbar_night:
                showProgress();
                // if (seekBar instanceof shuqiDefineSeekBar) {
                // mLastJumpProgress1 = ((shuqiDefineSeekBar) seekBar).getPercent();
                // }
                break;
            default:
                break;
        }
    }

    private static final int JUMPBAR_MAX_PROGRESS = 1000;


}
